package com.da.javatest.niuke.jianzhi;

/**
 * @author chenlida
 * @date 2020/10/22 15:45
 * https://www.nowcoder.com/practice/8fecd3f8ba334add803bf2a06af1b993?
 * tpId=13&tags=&title=&diffculty=0&judgeStatus=0&rp=1
 */
public class C32Solution {
    public static String PrintMinNumber(int[] numbers) {
        StringBuilder sb = new StringBuilder();
        int length = numbers.length;
        for (int i = 0; i < length; i++) {
            for (int j = i + 1; j < length; j++) {
                StringBuilder s1 = new StringBuilder(numbers[i] + "");
                StringBuilder s2 = new StringBuilder(numbers[j] + "");
                // 长度填充，比如3与32 最后会变成33与32对比
                if (s1.length() != s2.length()) {
                    if (s1.length() < s2.length()) {
                        while (s1.length() != s2.length()) {
                            s1.append(numbers[i] % 10);
                        }
                    } else {
                        while (s1.length() != s2.length()) {
                            s2.append(numbers[j] % 10);
                        }
                    }
                }
                // 大小对比交换
                if (s1.toString().compareTo(s2.toString()) > 0) {
                    int temp = numbers[i];
                    numbers[i] = numbers[j];
                    numbers[j] = temp;
                }
            }
        }
        for (int number : numbers) {
            sb.append(number);
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        System.out.println(PrintMinNumber(new int[] {3, 32, 321}));
    }
}
